package com.eagle.epay.listener;


import com.eagle.epay.entity.PayInfo;
import com.eagle.epay.service.IOrderService;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class FanoutReceiver {
	@Autowired
	private Environment env;

	@Autowired
	private IOrderService orderService;

	@RabbitListener(queues = "${epay.rabbitmq.fanout.queue.paynotify.name}" ,containerFactory = "singleListenerContainer")
    public void receivePayNotifyQueue(String message) {
		log.info("receive the message=>{}", message);
		PayInfo payInfo = new Gson().fromJson(message, PayInfo.class);
		orderService.paid(String.valueOf(payInfo.getOrderNo()));
    }



}
